<h1><code ng:non-bindable="">$httpBackend</code>
<span class="hint">(service in module <code ng:non-bindable="">ngMock</code>
)</span>
</h1>
<div><a href="http://github.com/angular/angular.js/edit/master/src/ngMock/angular-mocks.js"
        class="improve-docs btn btn-primary">Improve this doc</a>

    <h2 id="Description">Description</h2>

    <div class="description">
        <div class="ngmock-httpbackend-page"><p>Fake HTTP backend implementation suitable for unit testing applications
            that use the
            <a href="api/ng.$http"><code>$http service</code></a>.</p>

            <p><em>Note</em>: For fake HTTP backend implementation suitable for end-to-end testing or backend-less
                development please see <a href="api/ngMockE2E.$httpBackend">e2e $httpBackend mock</a>.</p>

            <p>During unit testing, we want our unit tests to run quickly and have no external dependencies so
                we don’t want to send <a href="https://developer.mozilla.org/en/xmlhttprequest">XHR</a> or
                <a href="http://en.wikipedia.org/wiki/JSONP">JSONP</a> requests to a real server. All we really need is
                to verify whether a certain request has been sent or not, or alternatively just let the
                application make requests, respond with pre-trained responses and assert that the end result is
                what we expect it to be.</p>

            <p>This mock implementation can be used to respond with static or dynamic responses via the
                <code>expect</code> and <code>when</code> apis and their shortcuts (<code>expectGET</code>, <code>whenPOST</code>,
                etc).</p>

            <p>When an Angular application needs some data from a server, it calls the $http service, which
                sends the request to a real server using $httpBackend service. With dependency injection, it is
                easy to inject $httpBackend mock (which has the same API as $httpBackend) and use it to verify
                the requests and respond with some testing data without sending a request to real server.</p>

            <p>There are two ways to specify what test data should be returned as http responses by the mock
                backend when the code under test makes http requests:</p>

            <ul>
                <li><code>$httpBackend.expect</code> - specifies a request expectation</li>
                <li><code>$httpBackend.when</code> - specifies a backend definition</li>
            </ul>

            <h1 id="requestexpectationsvsbackenddefinitions">Request Expectations vs Backend Definitions</h3>

                <p>Request expectations provide a way to make assertions about requests made by the application and
                    to define responses for those requests. The test will fail if the expected requests are not made
                    or they are made in the wrong order.</p>

                <p>Backend definitions allow you to define a fake backend for your application which doesn't assert
                    if a particular request was made or not, it just returns a trained response if a request is made.
                    The test will pass whether or not the request gets made during testing.</p>

                <table class="table">
                    <tr>
                        <th width="220px"></th>
                        <th>Request expectations</th>
                        <th>Backend definitions</th>
                    </tr>
                    <tr>
                        <th>Syntax</th>
                        <td>.expect(...).respond(...)</td>
                        <td>.when(...).respond(...)</td>
                    </tr>
                    <tr>
                        <th>Typical usage</th>
                        <td>strict unit tests</td>
                        <td>loose (black-box) unit testing</td>
                    </tr>
                    <tr>
                        <th>Fulfills multiple requests</th>
                        <td>NO</td>
                        <td>YES</td>
                    </tr>
                    <tr>
                        <th>Order of requests matters</th>
                        <td>YES</td>
                        <td>NO</td>
                    </tr>
                    <tr>
                        <th>Request required</th>
                        <td>YES</td>
                        <td>NO</td>
                    </tr>
                    <tr>
                        <th>Response required</th>
                        <td>optional (see below)</td>
                        <td>YES</td>
                    </tr>
                </table>

                <p>In cases where both backend definitions and request expectations are specified during unit
                    testing, the request expectations are evaluated first.</p>

                <p>If a request expectation has no response specified, the algorithm will search your backend
                    definitions for an appropriate response.</p>

                <p>If a request didn't match any expectation or if the expectation doesn't have the response
                    defined, the backend definitions are evaluated in sequential order to see if any of them match
                    the request. The response from the first matched definition is returned.</p>

                <h1 id="flushinghttprequests">Flushing HTTP requests</h3>

                    <p>The $httpBackend used in production, always responds to requests with responses asynchronously.
                        If we preserved this behavior in unit testing, we'd have to create async unit tests, which are
                        hard to write, follow and maintain. At the same time the testing mock, can't respond
                        synchronously because that would change the execution of the code under test. For this reason
                        the
                        mock $httpBackend has a <code>flush()</code> method, which allows the test to explicitly flush
                        pending
                        requests and thus preserving the async api of the backend, while allowing the test to execute
                        synchronously.</p>

                    <h1 id="unittestingwithmockdhttpbackend">Unit testing with mock $httpBackend</h3>

                        <p>The following code shows how to setup and use the mock backend in unit testing a controller.
                            First we create the controller under test</p>

<pre class="prettyprint linenums">
  // The controller code
  function MyController($scope, $http) {
    var authToken;

    $http.get('/auth.py').success(function(data, status, headers) {
      authToken = headers('A-Token');
      $scope.user = data;
    });

    $scope.saveMessage = function(message) {
      var headers = { 'Authorization': authToken };
      $scope.status = 'Saving...';

      $http.post('/add-msg.py', message, { headers: headers } ).success(function(response) {
        $scope.status = '';
      }).error(function() {
        $scope.status = 'ERROR!';
      });
    };
  }
  </pre>

                        <p>Now we setup the mock backend and create the test specs.</p>

<pre class="prettyprint linenums">
    // testing controller
    describe('MyController', function() {
       var $httpBackend, $rootScope, createController;

       beforeEach(inject(function($injector) {
         // Set up the mock http service responses
         $httpBackend = $injector.get('$httpBackend');
         // backend definition common for all tests
         $httpBackend.when('GET', '/auth.py').respond({userId: 'userX'}, {'A-Token': 'xxx'});

         // Get hold of a scope (i.e. the root scope)
         $rootScope = $injector.get('$rootScope');
         // The $controller service is used to create instances of controllers
         var $controller = $injector.get('$controller');

         createController = function() {
           return $controller('MyController', {'$scope' : $rootScope });
         };
       }));


       afterEach(function() {
         $httpBackend.verifyNoOutstandingExpectation();
         $httpBackend.verifyNoOutstandingRequest();
       });


       it('should fetch authentication token', function() {
         $httpBackend.expectGET('/auth.py');
         var controller = createController();
         $httpBackend.flush();
       });


       it('should send msg to server', function() {
         var controller = createController();
         $httpBackend.flush();

         // now you don’t care about the authentication, but
         // the controller will still send the request and
         // $httpBackend will respond without you having to
         // specify the expectation and response for this request

         $httpBackend.expectPOST('/add-msg.py', 'message content').respond(201, '');
         $rootScope.saveMessage('message content');
         expect($rootScope.status).toBe('Saving...');
         $httpBackend.flush();
         expect($rootScope.status).toBe('');
       });


       it('should send auth header', function() {
         var controller = createController();
         $httpBackend.flush();

         $httpBackend.expectPOST('/add-msg.py', undefined, function(headers) {
           // check if the header was send, if it wasn't the expectation won't
           // match the request and the test will fail
           return headers['Authorization'] == 'xxx';
         }).respond(201, '');

         $rootScope.saveMessage('whatever');
         $httpBackend.flush();
       });
    });
   </pre>
        </div>
    </div>
    <div class="member method"><h2 id="Methods">Methods</h2>
        <ul class="methods">
            <li><h3 id="expect">expect(method, url, data, headers)</h3>

                <div class="expect">
                    <div class="ngmock-httpbackend-expect-page"><p>Creates a new request expectation.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">method – {string} – </code>

                            <div class="ngmock-httpbackend-expect-page"><p>HTTP method.</p></div>
                        </li>
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expect-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp|function(string)|Object)=}
                            – </code>

                            <div class="ngmock-httpbackend-expect-page"><p>HTTP request body or function that
                                receives data string and returns true if the data is as expected, or Object if request
                                body
                                is in JSON format.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-expect-page"><p>HTTP headers or function that receives http
                                header
                                object and returns true if the headers match the current expectation.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expect-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p>

                            <ul>
                                <li>respond – <code>{function([status,] data[, headers])|function(function(method, url,
                                    data, headers)}</code>
                                    – The respond method takes a set of static data to be returned or a function that
                                    can return
                                    an array containing response status (number), response data (string) and response
                                    headers
                                    (Object).
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectDELETE">expectDELETE(url, headers)</h3>

                <div class="expectdelete">
                    <div class="ngmock-httpbackend-expectdelete-page"><p>Creates a new request expectation for DELETE
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expectdelete-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {Object=} – </code>

                            <div class="ngmock-httpbackend-expectdelete-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expectdelete-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectGET">expectGET(url, headers)</h3>

                <div class="expectget">
                    <div class="ngmock-httpbackend-expectget-page"><p>Creates a new request expectation for GET
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expectget-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {Object=} – </code>

                            <div class="ngmock-httpbackend-expectget-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expectget-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled. See #expect for more info.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectHEAD">expectHEAD(url, headers)</h3>

                <div class="expecthead">
                    <div class="ngmock-httpbackend-expecthead-page"><p>Creates a new request expectation for HEAD
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expecthead-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {Object=} – </code>

                            <div class="ngmock-httpbackend-expecthead-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expecthead-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectJSONP">expectJSONP(url)</h3>

                <div class="expectjsonp">
                    <div class="ngmock-httpbackend-expectjsonp-page"><p>Creates a new request expectation for JSONP
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expectjsonp-page"><p>HTTP url.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expectjsonp-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectPATCH">expectPATCH(url, data, headers)</h3>

                <div class="expectpatch">
                    <div class="ngmock-httpbackend-expectpatch-page"><p>Creates a new request expectation for PATCH
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expectpatch-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp|function(string)|Object)=}
                            – </code>

                            <div class="ngmock-httpbackend-expectpatch-page"><p>HTTP request body or function that
                                receives data string and returns true if the data is as expected, or Object if request
                                body
                                is in JSON format.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {Object=} – </code>

                            <div class="ngmock-httpbackend-expectpatch-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expectpatch-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectPOST">expectPOST(url, data, headers)</h3>

                <div class="expectpost">
                    <div class="ngmock-httpbackend-expectpost-page"><p>Creates a new request expectation for POST
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expectpost-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp|function(string)|Object)=}
                            – </code>

                            <div class="ngmock-httpbackend-expectpost-page"><p>HTTP request body or function that
                                receives data string and returns true if the data is as expected, or Object if request
                                body
                                is in JSON format.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {Object=} – </code>

                            <div class="ngmock-httpbackend-expectpost-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expectpost-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="expectPUT">expectPUT(url, data, headers)</h3>

                <div class="expectput">
                    <div class="ngmock-httpbackend-expectput-page"><p>Creates a new request expectation for PUT
                        requests. For more info see <code>expect()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-expectput-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp|function(string)|Object)=}
                            – </code>

                            <div class="ngmock-httpbackend-expectput-page"><p>HTTP request body or function that
                                receives data string and returns true if the data is as expected, or Object if request
                                body
                                is in JSON format.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {Object=} – </code>

                            <div class="ngmock-httpbackend-expectput-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-expectput-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="flush">flush(count)</h3>

                <div class="flush">
                    <div class="ngmock-httpbackend-flush-page"><p>Flushes all pending requests using the trained
                        responses.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">count<i>(optional)</i> – {number=} – </code>

                            <div class="ngmock-httpbackend-flush-page"><p>Number of responses to flush (in the order
                                they arrived). If undefined,
                                all pending requests will be flushed. If there are no pending requests when the flush
                                method
                                is called an exception is thrown (as this typically a sign of programming error).</p>
                            </div>
                        </li>
                    </ul>
                </div>
            </li>
            <li><h3 id="resetExpectations">resetExpectations()</h3>

                <div class="resetexpectations">
                    <div class="ngmock-httpbackend-resetexpectations-page"><p>Resets all request expectations, but
                        preserves all backend definitions. Typically, you would
                        call resetExpectations during a multiple-phase test when you want to reuse the same instance of
                        $httpBackend mock.</p></div>
                </div>
            </li>
            <li><h3 id="verifyNoOutstandingExpectation">verifyNoOutstandingExpectation()</h3>

                <div class="verifynooutstandingexpectation">
                    <div class="ngmock-httpbackend-verifynooutstandingexpectation-page"><p>Verifies that all of the
                        requests defined via the <code>expect</code> api were made. If any of the
                        requests were not made, verifyNoOutstandingExpectation throws an exception.</p>

                        <p>Typically, you would call this method following each test case that asserts requests using an
                            "afterEach" clause.</p>

<pre class="prettyprint linenums">
  afterEach($httpBackend.verifyNoOutstandingExpectation);
</pre>
                    </div>
                </div>
            </li>
            <li><h3 id="verifyNoOutstandingRequest">verifyNoOutstandingRequest()</h3>

                <div class="verifynooutstandingrequest">
                    <div class="ngmock-httpbackend-verifynooutstandingrequest-page"><p>Verifies that there are no
                        outstanding requests that need to be flushed.</p>

                        <p>Typically, you would call this method following each test case that asserts requests using an
                            "afterEach" clause.</p>

<pre class="prettyprint linenums">
  afterEach($httpBackend.verifyNoOutstandingRequest);
</pre>
                    </div>
                </div>
            </li>
            <li><h3 id="when">when(method, url, data, headers)</h3>

                <div class="when">
                    <div class="ngmock-httpbackend-when-page"><p>Creates a new backend definition.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">method – {string} – </code>

                            <div class="ngmock-httpbackend-when-page"><p>HTTP method.</p></div>
                        </li>
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-when-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp)=} – </code>

                            <div class="ngmock-httpbackend-when-page"><p>HTTP request body.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-when-page"><p>HTTP headers or function that receives http
                                header
                                object and returns true if the headers match the current definition.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-when-page"><p>Returns an object with <code>respond</code> method
                            that control how a matched
                            request is handled.</p>

                            <ul>
                                <li>respond – <code>{function([status,] data[, headers])|function(function(method, url,
                                    data, headers)}</code>
                                    – The respond method takes a set of static data to be returned or a function that
                                    can return
                                    an array containing response status (number), response data (string) and response
                                    headers
                                    (Object).
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </li>
            <li><h3 id="whenDELETE">whenDELETE(url, headers)</h3>

                <div class="whendelete">
                    <div class="ngmock-httpbackend-whendelete-page"><p>Creates a new backend definition for DELETE
                        requests. For more info see <code>when()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-whendelete-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-whendelete-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-whendelete-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="whenGET">whenGET(url, headers)</h3>

                <div class="whenget">
                    <div class="ngmock-httpbackend-whenget-page"><p>Creates a new backend definition for GET requests.
                        For more info see <code>when()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-whenget-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-whenget-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-whenget-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="whenHEAD">whenHEAD(url, headers)</h3>

                <div class="whenhead">
                    <div class="ngmock-httpbackend-whenhead-page"><p>Creates a new backend definition for HEAD requests.
                        For more info see <code>when()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-whenhead-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-whenhead-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-whenhead-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="whenJSONP">whenJSONP(url)</h3>

                <div class="whenjsonp">
                    <div class="ngmock-httpbackend-whenjsonp-page"><p>Creates a new backend definition for JSONP
                        requests. For more info see <code>when()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-whenjsonp-page"><p>HTTP url.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-whenjsonp-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="whenPOST">whenPOST(url, data, headers)</h3>

                <div class="whenpost">
                    <div class="ngmock-httpbackend-whenpost-page"><p>Creates a new backend definition for POST requests.
                        For more info see <code>when()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-whenpost-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp)=} – </code>

                            <div class="ngmock-httpbackend-whenpost-page"><p>HTTP request body.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-whenpost-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-whenpost-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
            <li><h3 id="whenPUT">whenPUT(url, data, headers)</h3>

                <div class="whenput">
                    <div class="ngmock-httpbackend-whenput-page"><p>Creates a new backend definition for PUT requests.
                        For more info see <code>when()</code>.</p></div>
                    <h4 id="Parameters">Parameters</h4>
                    <ul class="parameters">
                        <li><code ng:non-bindable="">url – {string|RegExp} – </code>

                            <div class="ngmock-httpbackend-whenput-page"><p>HTTP url.</p></div>
                        </li>
                        <li><code ng:non-bindable="">data<i>(optional)</i> – {(string|RegExp)=} – </code>

                            <div class="ngmock-httpbackend-whenput-page"><p>HTTP request body.</p></div>
                        </li>
                        <li><code ng:non-bindable="">headers<i>(optional)</i> – {(Object|function(Object))=} – </code>

                            <div class="ngmock-httpbackend-whenput-page"><p>HTTP headers.</p></div>
                        </li>
                    </ul>
                    <h4 id="Returns">Returns</h4>

                    <div class="returns"><code ng:non-bindable="">{requestHandler}</code>
                        –
                        <div class="ngmock-httpbackend-whenput-page"><p>Returns an object with <code>respond</code>
                            method that control how a matched
                            request is handled.</p></div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</div>
